<template>
  <div class="business-waybill-list">
    <div class="search-wrapper">
      <super-search :search-form="searchForm" :search-item-config="searchItemList" @search="searchHandle" v-model:showMore="showMore" :spanCount="4"></super-search>
    </div>
    <div class="content-wrapper">
      <a-tabs v-model:activeKey="activeKey" @change="changeTabHandle">
        <a-tab-pane key="5" :tab="`入仓(${pageStat['5']})`"></a-tab-pane>
        <a-tab-pane key="6" :tab="`出库(${pageStat['6']})`"></a-tab-pane>
        <a-tab-pane key="7" :tab="`出仓(${pageStat['7']})`"></a-tab-pane>
        <a-tab-pane key="8" :tab="`运输(${pageStat['8']})`"></a-tab-pane>
        <a-tab-pane key="9" :tab="`签收(${pageStat['9']})`"></a-tab-pane>
        <a-tab-pane key="-5" :tab="`扣货(${pageStat['-5']})`"></a-tab-pane>
        <a-tab-pane key="0" :tab="`取消(${pageStat['0']})`"></a-tab-pane>
        <a-tab-pane key="-2" :tab="`全部(${pageStat['-2']})`"></a-tab-pane>
      </a-tabs>
      <super-table
        :height="tableHeight"
        ref="tableRef"
        v-model:page="searchForm.pageNum"
        v-model:limit="searchForm.pageSize"
        :loading="loading"
        :data="tableData"
        :activeKey="activeKey"
        :total="searchForm.total"
        :column="tableColumn"
        :row-class-name="rowClassName"
        @change-page="getData"
        :sort-config="{ remote: true }"
        @sort-change="sortChangeHandle"
      >
        <template #tool>
          <div style="display: flex; justify-content: space-between">
            <div>
              <!-- <a-button v-if="activeKey === '5'" type="primary" @click="modifyChannelHandle">修改渠道</a-button>
                <a-button type="primary" @click="modifyChannelHandle">修改代理渠道</a-button>
               <a-button type="primary" @click="modifyProductNameHandle">品名</a-button>
               <a-button type="primary" @click="modifyMasterialHandle">材质</a-button> -->
              <!-- <a-button type="primary" v-if="activeKey !== '0'" @click="cancelShipmentHandle">取消运单</a-button> -->
              <a-button type="primary" v-if="activeKey !== '0'" @click="modifyRemarkHandle">批量修改客户备注</a-button>
              <a-button type="primary" v-if="activeKey !== '0'" @click="modifyInnerRemarkHandle">批量修改内部备注</a-button>
              <a-button type="primary" @click="makeInvoiceHandle" v-if="['5', '6'].includes(activeKey)" v-btnAuth="'BUSINESS_INVOICE'">制作发票</a-button>
              <a-button type="primary" v-if="activeKey !== '-2'" @click="updateTrackHandle" v-btnAuth="'WAYBILLLIST_UPDATE_TRACK'">更新运踪</a-button>
              <a-button type="primary" @click="addProblemShipment" v-if="activeKey !== '0'">发起问题件</a-button>
              <a-button type="primary" @click="showStatictisHandle">查看统计</a-button>
            </div>

            <!-- 导出 -->
            <div>
              <a-dropdown :getPopupContainer="getPopupContainer">
                <a-button type="primary" class="ant-dropdown-link" @click.prevent> 导出 <DownOutlined /></a-button>
                <template #overlay>
                  <a-menu>
                    <a-menu-item @click="templateExportHandle">使用模版导出</a-menu-item>
                    <a-menu-item @click="customExportHandle">自定义导出</a-menu-item>
                    <a-menu-item @click="invoiceExportHandle">发票导出</a-menu-item>
                    <a-menu-item @click="VolumeExportHandle">材积明细导出</a-menu-item>
                  </a-menu>
                </template>
              </a-dropdown>
            </div>
            <!-- 标签管理 -->
            <div v-if="['5', '6'].includes(activeKey)">
              <a-dropdown :getPopupContainer="getPopupContainer">
                <a-button type="primary" class="ant-dropdown-link" @click.prevent> 标签管理 <DownOutlined /></a-button>
                <template #overlay>
                  <a-menu>
                    <a-menu-item @click="printLabelHandle">打印标签</a-menu-item>
                    <a-menu-item @click="downloadLabelHandle(undefined)">下载标签</a-menu-item>
                    <a-menu-item @click="downloadLabelHandle(1)">合并下载</a-menu-item>
                  </a-menu>
                </template>
              </a-dropdown>
            </div>

            <!-- 合并报关 -->
            <div v-if="['5', '6'].includes(activeKey)" v-btnAuth="'BUSINESSWAYBILL_CUSTOMS_CLEARANCE'">
              <a-dropdown :getPopupContainer="getPopupContainer">
                <a-button type="primary" class="ant-dropdown-link" @click.prevent> 报关管理 <DownOutlined /></a-button>
                <template #overlay>
                  <a-menu>
                    <a-menu-item @click="customsClearanceHandle">合并报关</a-menu-item>
                    <a-menu-item @click="cancelMergeDeclarationHandle">取消报关</a-menu-item>
                  </a-menu>
                </template>
              </a-dropdown>
            </div>
          </div>
        </template>
        <template #addressType="{ row }">
          <a-tag v-if="row.addressType === 'AMAZON'" color="#108ee9">{{ getLabelByDict("WAYBILL_TYPE", row.addressType) }}</a-tag>
          <a-tag v-if="row.addressType === 'WALMART'" color="#2db7f5">{{ getLabelByDict("WAYBILL_TYPE", row.addressType) }}</a-tag>
          <a-tag v-if="row.addressType === 'PERSONALWAR'" color="#f50">{{ getLabelByDict("WAYBILL_TYPE", row.addressType) }}</a-tag>
        </template>
        <template #waybillNum="{ row }">
          <a-button type="link" @click="showHandle(row)">{{ row.waybillNum }}</a-button>
        </template>
        <template #makeInvoiceStatus="{ row }">
          <a-tag v-if="row.makeInvoiceStatus === -1" color="#f50">未做发票 </a-tag>
          <a-tag v-if="row.makeInvoiceStatus === -2" color="#87d068"> 已做发票 </a-tag>
        </template>
        <template #status="{ row }">
          <a-tag v-if="row.status === 1" color="#009688"> 已下单 </a-tag>
          <a-tag v-if="row.status === 5" color="#CD5C5C"> 已入仓 </a-tag>
          <a-tag v-if="row.status === 6" color="#FFE4E1"> 出库 </a-tag>
          <a-tag v-if="row.status === 7" color="#2db7f5"> 出仓 </a-tag>
          <a-tag v-if="row.status === 8" color="#108ee9"> 运输中 </a-tag>
          <a-tag v-if="row.status === 9" color="#87d068"> 签收 </a-tag>
          <a-tag v-if="row.status === -5" color="#f50"> 扣货 </a-tag>
          <a-tag v-if="row.status === 0" color="#9AFF9A"> 已取消 </a-tag>
        </template>

        <template #action="{ row }">
          <a-button type="link" @click="showLogHandle(row)">日志</a-button>
        </template>
      </super-table>
    </div>
    <!-- 抽屉 -->
    <a-drawer class="custom-drawer" v-model:visible="drawerOpts.visible" :title="drawerOpts.title" :closable="true" @close="drawerOpts.visible = false" :width="drawerOpts.width" placement="right">
      <component
        v-model:visible="drawerOpts.visible"
        :sysModule="'运单管理'"
        :is="drawerOpts.component"
        :logId="drawerOpts.passData?.id"
        :type="drawerOpts.type"
        :activeKey="activeKey"
        :pass-data="drawerOpts.passData"
        :requestFn="requestFn"
        @submit="drawerOpts.visible = false"
      ></component>
    </a-drawer>
    <!-- 弹窗 -->
    <a-modal
      v-model:visible="dialogOpts.visible"
      :maskClosable="false"
      :keyboard="false"
      :closable="['DataStatistics'].includes(dialogOpts.component)"
      :footer="null"
      :title="dialogOpts.title"
      :width="dialogOpts.width"
    >
      <component
        v-model:visible="dialogOpts.visible"
        :init="getStatisticsDataFn"
        :column="statisticsColumn"
        :is="dialogOpts.component"
        :type="dialogOpts.type"
        :pass-data="dialogOpts.passData"
        @submit="dialogSubmitHandle"
      ></component>
    </a-modal>
  </div>
</template>
<script lang="ts">
import Details from "./components/details/index.vue";
import ModifyChannel from "./components/modifyChannel/index.vue";
import ModifyProductName from "./components/modifyProductName/index.vue";
import ModifyMasterial from "./components/modifyMasterial/index.vue";
import ModifyRemark from "./components/modifyRemark/index.vue";
import TemplateExport from "./components/templateExport/index.vue";
import CustomExport from "./components/customExport/index.vue";
import DataStatistics from "@/components/dataStatistics/index.vue";
import MakeInvoice from "../../stockManagement/components/makeInvoice/index.vue";
import InvoiceExport from "./components/InvoiceExport/index.vue";
import OperationLog from "@/components/operationLog/index.vue";
import ProblemShipment from "@/views/waybillManagement/customerServiceWaybill/components/problemShipment/index.vue";

export default {
  name: "BusinessWaybillList",
  components: {
    Details,
    ModifyChannel,
    ModifyProductName,
    ModifyMasterial,
    ModifyRemark,
    TemplateExport,
    CustomExport,
    DataStatistics,
    MakeInvoice,
    OperationLog,
    InvoiceExport,
    ProblemShipment
  }
};
</script>
<script lang="ts" setup>
import TableHeightHook from "@/hook/tableHeightHook";
import ModalHook from "@/hook/modalHook";
import { searchItemList, tableColumn, statisticsColumn } from "./data";
import InitHook from "./composables/initHook";
import OperationHook from "./composables/operationHook";
import { DownOutlined } from "@ant-design/icons-vue";
import CommonHook from "@/hook/commonHook";
import TableHook from "@/hook/tableHook";
const { getLabelByDict } = CommonHook();

const { tableHeight, loading, showMore } = TableHeightHook(110);
const { searchForm, tableData, tableRef, dialogOpts, drawerOpts, saPageInfo, activeKey, pageStat, getPopupContainer, rowClassName } = InitHook();
const {
  searchHandle,
  getData,
  showHandle,
  modifyRemarkHandle,
  modifyInnerRemarkHandle,
  changeTabHandle,
  getStatisticsDataFn,
  showStatictisHandle,
  templateExportHandle,
  customExportHandle,
  makeInvoiceHandle,
  printLabelHandle,
  downloadLabelHandle,
  showLogHandle,
  requestFn,
  invoiceExportHandle,
  VolumeExportHandle,
  customsClearanceHandle,
  cancelMergeDeclarationHandle,
  updateTrackHandle,
  addProblemShipment
} = OperationHook({
  searchForm,
  tableData,
  tableRef,
  dialogOpts,
  drawerOpts,
  saPageInfo,
  loading,
  activeKey,
  pageStat
});
const { sortChangeHandle } = TableHook({ searchForm }, searchHandle);
searchHandle();
const { dialogSubmitHandle } = ModalHook({
  drawerOpts,
  dialogOpts,
  callBack: () => getData()
});
</script>
<style lang="stylus" scoped>
.business-waybill-list{
  :deep() {
    .vxe-body--row.red-row {
        background-color: #fef0f0;
        color: #f56c6c;
    }

    .vxe-body--row.yellow-row {
        background-color: #fdf6ec;
        color: #e6a23c;
    }

    .vxe-body--row.orange-row {
        background-color: #d3d3d3;
        color: red;
    }
  }
}
</style>
